package com.example.project.uediter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@RestController
@RequestMapping("/mh/ueditor")
@CrossOrigin(allowCredentials = "true")
public class UeditorController {
    private static Logger logger = LoggerFactory.getLogger(UeditorController.class);

    @RequestMapping(value="/config")
    public void config(HttpServletRequest request, HttpServletResponse response, String action, MultipartFile upfile) {
//        if(action.equals("config")){
            response.setContentType("application/json");

            String rootPath = request.getSession().getServletContext().getRealPath("/");

        logger.info("rootPath:::===================================================>{}",rootPath);
            try {

                String exec = new ActionEnter(request, rootPath).exec();
                PrintWriter writer = response.getWriter();
                writer.write(exec);
                writer.flush();
                writer.close();

            } catch(IOException e) {
                e.printStackTrace();
            }
//        }else if(action.equals("uploadimage")){
//
//        }
    }
}